package com.admin.application;

import com.admin.domain.modle.Member;
import com.admin.domain.repository.MemberRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;


/**
 * description
 * User: WeiDa
 * Date: 2017-4-11
 * Time: 16:45
 */
@Service
@CacheConfig(cacheNames = "member")
public class MemberService {

    private static final Logger LOGGER = LoggerFactory.getLogger(MemberService.class);
    @Autowired
    protected MemberRepository memberRepository;

    public Member create(Member member) {
        member.setId(UUID.randomUUID().toString());
        memberRepository.add(member);
        return member;
    }

    public Member modify(Member member) {
        memberRepository.update(member);
        return member;
    }

    public Member getByOpenId(String openId) {
        return memberRepository.getById(openId);
    }

    public List<Member> list(String key) {
        return memberRepository.list(key);
    }

    public void delete(String id) {
        memberRepository.remove(id);
    }
}
